package com.wshl.aijiuunion.view.adapter;

import android.content.Intent;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SPUtils;
import com.wshl.aijiuunion.GlobConstant;
import com.wshl.aijiuunion.NetUrl;
import com.wshl.aijiuunion.R;
import com.wshl.aijiuunion.controller.activity.WebActivity;
import com.wshl.aijiuunion.utils.share.LoginOutUtils;
import com.wshl.aijiuunion.view.bean.GoodsBean;
import com.wshl.aijiuunion.utils.GlideUtils;

import cn.bingoogolapple.baseadapter.BGAOnRVItemClickListener;
import cn.bingoogolapple.baseadapter.BGARecyclerViewAdapter;
import cn.bingoogolapple.baseadapter.BGAViewHolderHelper;

/**
 * Created buy 风凊扬 on 2019/10/24 0024
 */
public class GoodsAdapter extends BGARecyclerViewAdapter<GoodsBean> implements BGAOnRVItemClickListener {
    public GoodsAdapter(RecyclerView recyclerView) {
        super(recyclerView, R.layout.item_goods);
        setOnRVItemClickListener(this);
    }

    @Override
    protected void fillData(BGAViewHolderHelper helper, int position, GoodsBean model) {

        helper.setText(R.id.tv_goodsname, model.getTitle());
        helper.setText(R.id.tv_count, "剩余" + model.getSku() + "件");
        helper.setText(R.id.tv_sale_count, "已售" + model.getSales());
        helper.setText(R.id.tv_goods_price, "¥" + model.getPrice());
        // helper.setText(R.id.tv_old_price, "¥" + model.getOld_price());
        TextView tvOldPrice = helper.getTextView(R.id.tv_old_price);
        tvOldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        tvOldPrice.setText("¥" + model.getOld_price());
        ImageView imageView = helper.getImageView(R.id.img_goods);
        GlideUtils.loadImage(mContext, NetUrl.IMG + model.getCover(), imageView);
    }

    @Override
    public void onRVItemClick(ViewGroup parent, View itemView, int position) {

        GoodsBean goodsBean = getData().get(position);
        int id = goodsBean.getId();
        String token = SPUtils.getInstance().getString(GlobConstant.TOKEN);
        Intent intent = new Intent(mContext, WebActivity.class);
        intent.putExtra(GlobConstant.WEBURL, NetUrl.GOODSDETAILS + token + "&id=" + id);
        ActivityUtils.startActivity(intent);
    }
}
